package kk.yiyi.safedesign.sms;

import android.Manifest;
import android.app.Activity;
import android.content.pm.PackageManager;
import android.os.Build;
import android.telephony.SmsManager;

import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;

import kk.yiyi.safedesign.base.Constants;
import kk.yiyi.safedesign.base.SharePresenterUtils;

import static android.Manifest.permission.SEND_SMS;

public class SmsUtils {
    public static void requestPermission(Activity activity) {
        //判断Android版本是否大于23
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            int checkCallPhonePermission = ContextCompat.checkSelfPermission(activity, Manifest.permission.CALL_PHONE);
            if (checkCallPhonePermission != PackageManager.PERMISSION_GRANTED) {
                ActivityCompat.requestPermissions(activity, new String[]{SEND_SMS}, 100);
                return;
            } else {
                sendSMSS(SharePresenterUtils.getData(activity, Constants.TABLE,"user"),"这贼人，换手机了");
                //已有权限
            }
        } else {
            //API 版本在23以下
        }
    }

    //发送短信
    public static void sendSMSS(String oldPhone,String newPhone) {


            SmsManager manager = SmsManager.getDefault();

                manager.sendTextMessage(oldPhone, null, "新手机号码为："+newPhone, null, null);


    }

}
